1 00:00:00,590 --> 00:00:02,990 Welcome to get started on our project. 2 00:00:02,990 --> 00:00:06,020 We're first going to work on our drink class for the server. 3 00:00:06,020 --> 00:00:08,570 We're actually going to have two drink classes. 4 00:00:08,570 --> 00:00:11,540 One is going to be for the client and one's going to be for the server. 5 00:00:11,540 --> 00:00:16,550 The purpose of the server drink class is to create drink objects on the server, and verify any information 6 00:00:16,550 --> 00:00:19,970 coming from the client for the creation and consumption of drinks. 7 00:00:19,970 --> 00:00:24,320 The purpose of the client drink class is to connect events to our drink tool that gets added to our 8 00:00:24,320 --> 00:00:28,190 inventory, and then do all the fun stuff with the drink text on our screen. 9 00:00:28,190 --> 00:00:33,200 So let's get started with the server side of drink class and the pre-made drinks module script, so 10 00:00:33,200 --> 00:00:36,440 we can go into replicated storage into our assets folder. 11 00:00:36,740 --> 00:00:41,810 And what I'm going to fill out is the pre-made drinks module script, because we want to be able to 12 00:00:41,810 --> 00:00:44,930 define all of the properties that we need for our drinks. 13 00:00:44,930 --> 00:00:49,040 So specifically in this module script, first I'm going to define the sound service. 14 00:00:49,040 --> 00:00:53,780 And that's because I want to be able to get access to all those different audio files we have inside 15 00:00:53,780 --> 00:00:55,160 of the sound service. 16 00:00:55,160 --> 00:01:00,020 And then from this point, I can also define some constants that we can use to create our custom drink. 17 00:01:00,020 --> 00:01:04,520 So one can be a dispense message that will set for basically almost every single drink. 18 00:01:04,520 --> 00:01:07,940 It'll just be a message that just says dispensing. 19 00:01:07,940 --> 00:01:09,710 And we'll just do three dots. 20 00:01:09,710 --> 00:01:15,140 And then we could do the same thing for let's say they input a drink and that drink doesn't exist. 21 00:01:15,140 --> 00:01:19,550 Then we could just do out message and set it to out of range. 22 00:01:20,760 --> 00:01:23,010 And now we can create a table for this module script. 23 00:01:23,010 --> 00:01:24,720 I'm just going to call it module. 24 00:01:24,750 --> 00:01:27,510 Doesn't really need to be named anything fancy. 25 00:01:27,510 --> 00:01:35,730 And then I'm going to create a reference to the sounds folder and sound service and get SCP 294 sounds. 26 00:01:35,730 --> 00:01:41,880 And then I'll create a table that contains all these sounds that we can pick of for dispensing and consuming 27 00:01:41,880 --> 00:01:42,630 our drink. 28 00:01:42,630 --> 00:01:47,310 So one section here will be for dispense sounds, and we'll set it to a table. 29 00:01:47,310 --> 00:01:51,900 And the second one will be for consume sounds and set that to a table as well. 30 00:01:51,900 --> 00:01:58,320 And inside of this table we can set the first dispense sound to be equal to the sounds folder. 31 00:01:58,650 --> 00:02:01,050 And there should be a folder in there called GUI. 32 00:02:01,050 --> 00:02:03,450 And we get the dispense sound. 33 00:02:04,200 --> 00:02:08,490 And then we can go ahead and do it for the dispense sound. 34 00:02:08,490 --> 00:02:10,530 And this one will be no liquid. 35 00:02:10,530 --> 00:02:14,730 So for example if they get a cup of air we don't want any liquid dispensing sound. 36 00:02:14,730 --> 00:02:19,770 So sounds folder GUI, dot dispense. 37 00:02:19,770 --> 00:02:21,090 And I believe it's no liquid. 38 00:02:21,090 --> 00:02:21,840 There it is. 39 00:02:21,840 --> 00:02:24,060 And we're just going to do this for all of them. 40 00:02:28,030 --> 00:02:29,920 And the last one is struggle. 41 00:02:33,230 --> 00:02:36,740 And again, we're going to do the same thing for our consumption. 42 00:02:36,740 --> 00:02:37,160 Sounds. 43 00:02:37,160 --> 00:02:40,520 So one's going to be a good consumption sound. 44 00:02:40,520 --> 00:02:42,830 So they drink and they're like hmm tasted good. 45 00:02:43,010 --> 00:02:45,530 And that's going to be drink good. 46 00:02:46,460 --> 00:02:51,830 Um, the next one we'll have is consume you one. 47 00:02:51,830 --> 00:02:57,590 And that sounds folder dot g dot drink you one. 48 00:03:00,160 --> 00:03:00,400 Oops. 49 00:03:00,400 --> 00:03:01,600 Forgot to put a comma there. 50 00:03:02,810 --> 00:03:04,310 We'll do it for the second one. 51 00:03:11,770 --> 00:03:13,210 The spit sound. 52 00:03:14,350 --> 00:03:17,350 We'll do one for when they drink and they get burned. 53 00:03:19,900 --> 00:03:23,320 And then we'll do one for the drink and the cough. 54 00:03:26,070 --> 00:03:29,490 And I'm not going to make a reference to the regular drink sound. 55 00:03:29,490 --> 00:03:33,900 What we could do is that if they don't put any drink sounds or they don't define a drink sound for a 56 00:03:33,900 --> 00:03:37,350 drink, then we'll just use the regular default drinking sound. 57 00:03:38,190 --> 00:03:45,960 So after that, then we can create a table that contains, um, all of the strings that can be used 58 00:03:45,960 --> 00:03:47,670 to dispense the specific drink. 59 00:03:47,670 --> 00:03:53,100 So for example, if we wanted a cup of air, the player could type in air or they could type in nothing, 60 00:03:53,100 --> 00:03:56,070 or they could type in emptiness, a vacuum, whatever. 61 00:03:56,070 --> 00:03:59,100 We all want them to refer to the same drink. 62 00:03:59,100 --> 00:04:04,440 So what I could do inside the module script is I'll create a table and I'll just call it current names. 63 00:04:05,170 --> 00:04:07,750 And these are going to be all the drinks we're going to have in our shop. 64 00:04:07,750 --> 00:04:12,910 So one is going to be air, and I'll just set the key to be air, and I'll set it equal to a table. 65 00:04:12,910 --> 00:04:18,160 And this table is going to be an array that contains a bunch of strings, that contains all the strings 66 00:04:18,160 --> 00:04:21,010 we can use for dispensing this particular drink. 67 00:04:21,010 --> 00:04:22,720 So one would be air. 68 00:04:22,750 --> 00:04:25,870 Another would be something like cup. 69 00:04:25,870 --> 00:04:30,040 Another could be like nothing, a vacuum. 70 00:04:30,040 --> 00:04:32,770 And we could be even a little funny and stick to the law. 71 00:04:32,770 --> 00:04:36,820 And we could do like air l three, which means half life three. 72 00:04:36,820 --> 00:04:39,610 So a cup of half life three, which doesn't exist. 73 00:04:39,610 --> 00:04:42,040 And we could also do a string that's empty. 74 00:04:42,040 --> 00:04:45,460 So these are all things the player could enter and get a cup of air from. 75 00:04:45,730 --> 00:04:50,140 And then the next thing we could do is we could create a table and we'll call it current drinks. 76 00:04:50,410 --> 00:04:53,470 And it's going to have the same keys that are in here. 77 00:04:53,470 --> 00:04:55,330 So we'll have one for air. 78 00:04:55,330 --> 00:04:59,740 And this is going to define all of the properties for this particular drink. 79 00:04:59,740 --> 00:05:01,930 So we could create a table here. 80 00:05:01,930 --> 00:05:05,260 And inside this table we can define all the things for the air drink. 81 00:05:05,260 --> 00:05:11,110 So for example the color of the liquid we could set the transparency for air to one because there's 82 00:05:11,110 --> 00:05:12,970 nothing for the color. 83 00:05:12,970 --> 00:05:16,300 We could just set to a new color three. 84 00:05:17,220 --> 00:05:20,400 That's just nothing because again, it's going to be completely transparent. 85 00:05:21,960 --> 00:05:24,540 The material again, it could be nothing. 86 00:05:24,540 --> 00:05:29,160 We're going to actually set defaults for this inside of our module script. 87 00:05:29,160 --> 00:05:31,170 So we don't really have to worry about this too much. 88 00:05:31,170 --> 00:05:39,000 We can set something like the dispense message to be equal to the the dispense message constant we set. 89 00:05:40,150 --> 00:05:46,870 Consume message could be something like there is nothing in the cup and this will display on that player 90 00:05:46,870 --> 00:05:47,590 screen. 91 00:05:48,420 --> 00:05:56,790 For the dispense sound, we could do something like refer to the sounds that are inside of dispense 92 00:05:56,790 --> 00:05:57,330 sound. 93 00:05:57,330 --> 00:06:01,080 So dispense sounds and get the dispense sound. 94 00:06:01,080 --> 00:06:03,750 No liquid because we're dispensing a cup of air. 95 00:06:04,680 --> 00:06:05,790 Don't forget that comma. 96 00:06:06,680 --> 00:06:13,190 And since it's going to be empty, there's really no point for us to define a particular, uh, consume 97 00:06:13,190 --> 00:06:13,850 sound for it. 98 00:06:13,850 --> 00:06:15,140 So we'll just leave that empty. 99 00:06:15,140 --> 00:06:16,730 But I will set a property in here. 100 00:06:16,730 --> 00:06:19,940 We'll call it is empty, and we'll set it to true. 101 00:06:19,940 --> 00:06:24,050 That means this cup is going to be empty when it gets dispensed, and the player isn't going to be able 102 00:06:24,050 --> 00:06:25,790 to drink it because there's nothing in the cup. 103 00:06:25,790 --> 00:06:28,880 And then last but not least, we can set a name for the cup. 104 00:06:28,880 --> 00:06:31,370 And the cup name here is just going to be air. 105 00:06:31,370 --> 00:06:36,590 And then we could like attach a string to the beginning of the string and say cup of air later on. 106 00:06:36,590 --> 00:06:41,120 But this is kind of how we can set up all of the drinks that we want to have in our game. 107 00:06:41,120 --> 00:06:45,290 And then of course, at the very end of this module script, we're going to go ahead and return the 108 00:06:45,290 --> 00:06:46,280 module table. 109 00:06:46,280 --> 00:06:49,460 So we have access to all these nice little properties here. 110 00:06:49,820 --> 00:06:50,090 All right. 111 00:06:50,120 --> 00:06:51,530 Now next comes the fun part. 112 00:06:51,530 --> 00:06:56,330 We're going to start working on the module script or the drink class for the server. 113 00:06:56,330 --> 00:06:58,850 What I'm going to do is I'm going to duplicate this. 114 00:06:58,850 --> 00:07:00,800 I'm going to get rid of all these children. 115 00:07:00,800 --> 00:07:03,710 And I'm going to name this one drink class. 116 00:07:03,710 --> 00:07:08,030 And we'll put some brackets and a C in here to define that. 117 00:07:08,030 --> 00:07:09,740 This is the client's drink class. 118 00:07:09,740 --> 00:07:12,050 So we'll fill this one out in the next lecture. 119 00:07:12,050 --> 00:07:13,640 But let's go ahead and fill out this one. 120 00:07:13,640 --> 00:07:17,810 And I'll rename it to bracket S to denote it as the server. 121 00:07:17,810 --> 00:07:20,420 And in here we're going to need quite a few services. 122 00:07:20,420 --> 00:07:23,150 One service is the Http service. 123 00:07:23,920 --> 00:07:29,230 And we're going to use this to generate a custom ID for every single drink in our game, because we 124 00:07:29,230 --> 00:07:35,860 want to be able to get drink objects of a specific ID from the client, and we don't want to base that 125 00:07:35,860 --> 00:07:40,120 on maybe the owner of the drink, because a player could be holding multiple drinks, and we want to 126 00:07:40,120 --> 00:07:46,510 get a specific drink object so we can put an ID, a custom ID that exists in each object. 127 00:07:46,510 --> 00:07:49,600 And we use that using the Http service. 128 00:07:49,600 --> 00:07:55,120 We'll get a reference to replicated storage, so we can get access to all the assets for our SCP. 129 00:07:56,420 --> 00:08:01,340 We're going to use the run service to make sure that whatever requires this module script is running 130 00:08:01,340 --> 00:08:02,300 on the server. 131 00:08:03,210 --> 00:08:04,950 And you'll see what I mean in a moment. 132 00:08:05,990 --> 00:08:09,290 And last but not least, we'll get a reference to the sound service. 133 00:08:13,120 --> 00:08:13,390 All right. 134 00:08:13,390 --> 00:08:14,770 I think we're good there for services. 135 00:08:14,770 --> 00:08:16,630 Now it's time to create some variables. 136 00:08:16,630 --> 00:08:20,080 So I'm going to create a variable called is server. 137 00:08:20,080 --> 00:08:23,920 And it's going to store the result from the run services function is server. 138 00:08:23,920 --> 00:08:28,600 So this returns a boolean telling you whether or not the context for the script is running on the client 139 00:08:28,600 --> 00:08:29,800 or running on the server. 140 00:08:29,800 --> 00:08:35,560 So did a server script require this module script or did a local script require this module script? 141 00:08:35,560 --> 00:08:41,470 And since this module script is only going to be for the server if the client or an exporter tries to 142 00:08:41,470 --> 00:08:44,050 require this module script, then we're just going to return nothing. 143 00:08:44,050 --> 00:08:44,920 So we could do. 144 00:08:44,920 --> 00:08:49,930 If not is server, then we'll just return an empty table and that's it. 145 00:08:50,770 --> 00:08:54,910 Otherwise, from that point we can create a table to represent our class. 146 00:08:54,910 --> 00:08:56,290 So I'll just call it drink. 147 00:08:56,290 --> 00:09:00,550 And I'll also have a table to represent the meta table for our class. 148 00:09:00,550 --> 00:09:02,680 So we uphold encapsulation. 149 00:09:02,680 --> 00:09:10,450 And we'll make sure to set the underscore underscore index meta method equal to the drink meta table 150 00:09:10,480 --> 00:09:11,830 table itself. 151 00:09:11,830 --> 00:09:15,280 So that way we can get access to all the little neat functions in our meta table. 152 00:09:15,550 --> 00:09:20,770 From this point I'm going to create a reference to our cup tool which is just script dot drink cup. 153 00:09:21,160 --> 00:09:27,460 I want a reference to the request event inside of replicated storage that's going to be replicated storage 154 00:09:28,330 --> 00:09:30,670 the assets folder and git request. 155 00:09:30,670 --> 00:09:33,640 And we'll do the same thing for the communications event. 156 00:09:36,590 --> 00:09:38,480 And then I'm going to create a table. 157 00:09:38,480 --> 00:09:39,890 I'll call it Current drinks. 158 00:09:39,890 --> 00:09:42,050 And this table is going to act as a cache. 159 00:09:42,050 --> 00:09:46,010 So every single drink object that gets created in my game, I'm going to store inside of this current 160 00:09:46,010 --> 00:09:46,970 drinks table. 161 00:09:46,970 --> 00:09:48,800 That way we can access them later on. 162 00:09:48,800 --> 00:09:54,080 For clients that need to request a drink object, then we're going to also refer to those two module 163 00:09:54,080 --> 00:09:57,800 scripts, which is the pre-made drinks functions and pre-made drinks module scripts. 164 00:09:57,800 --> 00:10:04,580 So we can have one pre-made drinks equal to require script dot pre-made drinks. 165 00:10:04,580 --> 00:10:06,830 And then we could do the same for the functions. 166 00:10:13,710 --> 00:10:19,380 And then to help with some randomization we're going to use later, I'll create a new random data type. 167 00:10:19,380 --> 00:10:26,730 And then now for the constructor of our class I want to be able to enforce, uh, whoever is scripting 168 00:10:26,730 --> 00:10:34,950 in our game to input things into the constructor, uh, like in a specific order, or showing us specifically 169 00:10:34,950 --> 00:10:37,950 what the drink constructor needs. 170 00:10:37,950 --> 00:10:43,170 So what I could do is I could create a custom type, I'll call it drink properties. 171 00:10:43,830 --> 00:10:45,630 And we'll set it equal to a table. 172 00:10:45,630 --> 00:10:50,160 And now inside of this table we want several things in order to create a drink. 173 00:10:50,160 --> 00:10:55,350 First off, perhaps when we create a new drink object, we want to set an owner for it so we can have 174 00:10:55,350 --> 00:10:56,610 an owner key value pair. 175 00:10:56,610 --> 00:10:57,840 And we can make this optional. 176 00:10:57,840 --> 00:10:59,640 So we'll just set it to player question mark. 177 00:10:59,640 --> 00:11:02,310 So this may or may not get passed in the table. 178 00:11:02,310 --> 00:11:05,370 We obviously want a name for our drink cup. 179 00:11:05,370 --> 00:11:07,140 So we'll set that to the string. 180 00:11:07,170 --> 00:11:15,090 We want to be able to access the key that this pre-made drink was made from. 181 00:11:15,090 --> 00:11:19,710 So specifically here we want to be able to access this particular key, just in case. 182 00:11:19,710 --> 00:11:25,320 We need to access any information like the strings in here or any of the information here down the line. 183 00:11:25,320 --> 00:11:29,340 So we'll store the pre-made key in here just in case. 184 00:11:29,850 --> 00:11:33,870 And then we want to define the properties for the liquid that's going to be in our cup. 185 00:11:33,870 --> 00:11:35,850 So we can call it liquid properties. 186 00:11:35,850 --> 00:11:38,880 And it's also going to be a table. 187 00:11:38,880 --> 00:11:44,280 And this table is going to have, you know the transparency for the drink, which is a number. 188 00:11:44,280 --> 00:11:48,780 It's going to have a color for the liquid which again is a color three. 189 00:11:48,780 --> 00:11:52,470 And then we're going to have a material for the liquid. 190 00:11:52,470 --> 00:11:54,810 And that's going to be enum dot material. 191 00:11:55,200 --> 00:11:58,950 Another key value pair we need to define is the dispense message. 192 00:11:58,950 --> 00:12:00,090 That will be a string. 193 00:12:01,010 --> 00:12:03,470 We'll need a consume message again. 194 00:12:03,470 --> 00:12:04,640 That'll be a string. 195 00:12:04,640 --> 00:12:09,290 And we could also set it to a table that contains strings. 196 00:12:09,470 --> 00:12:11,330 So like an array of strings. 197 00:12:12,060 --> 00:12:17,940 And we could do that to perhaps make a randomly generated message for when a player consumes a drink. 198 00:12:17,940 --> 00:12:22,590 So let's say you want to have more than one message for a particular drink, and you want to pick a 199 00:12:22,590 --> 00:12:24,330 message at random from a table. 200 00:12:24,330 --> 00:12:25,620 We can do that right here. 201 00:12:25,620 --> 00:12:30,180 We'll just define it to be either a string or a table containing strings. 202 00:12:30,600 --> 00:12:34,110 And then we'll need a dispense sound for this object. 203 00:12:34,110 --> 00:12:36,030 And that'll be a sound instance. 204 00:12:36,030 --> 00:12:40,110 And then we'll need a consume sound a sound instance. 205 00:12:40,110 --> 00:12:45,660 And then last but not least, that boolean that tells us whether or not the cup will be empty when it 206 00:12:45,660 --> 00:12:46,920 gets dispensed. 207 00:12:46,920 --> 00:12:47,970 We'll set that to a boolean. 208 00:12:48,480 --> 00:12:51,180 Now this is our custom type right here. 209 00:12:51,660 --> 00:12:57,300 Now you may be wondering, well, if I require this module script and a server script, how am I going 210 00:12:57,300 --> 00:13:00,900 to be able to see this type here if it doesn't belong to our drink table? 211 00:13:00,900 --> 00:13:02,400 That's a good question. 212 00:13:02,400 --> 00:13:06,660 And we can't set this drink properties inside of this table. 213 00:13:06,660 --> 00:13:08,130 So how the heck do we do it? 214 00:13:08,280 --> 00:13:12,120 Well, we can use another keyword in Lua you called export. 215 00:13:12,850 --> 00:13:17,890 And that means we're exporting this custom type to be part of the table that gets returned from this 216 00:13:17,890 --> 00:13:18,760 module script. 217 00:13:18,760 --> 00:13:23,440 So that means if we index our drink table, we'll be able to see this particular drinks property type, 218 00:13:23,440 --> 00:13:28,660 this custom type, and we'll be able to fill out all of these different key value pairs that we need 219 00:13:28,660 --> 00:13:30,700 in order to use our constructor. 220 00:13:30,700 --> 00:13:36,340 Now that does mean because we have all these requirements, what if someone who's scripting forgets 221 00:13:36,340 --> 00:13:38,470 to, you know, include one of these properties? 222 00:13:38,470 --> 00:13:40,540 Well, we can create some defaults. 223 00:13:40,540 --> 00:13:43,090 So I'm going to create a table call. 224 00:13:43,090 --> 00:13:47,560 It defaults and it's going to represent constants which is why I'm capitalizing it. 225 00:13:47,680 --> 00:13:51,670 And in here we can set a bunch of different defaults for all of these properties. 226 00:13:51,670 --> 00:13:55,960 So for example the liquid we can call it cup properties. 227 00:13:56,080 --> 00:14:00,640 And the default can be like maybe the transparency will be zero. 228 00:14:00,670 --> 00:14:03,190 The color will just be black. 229 00:14:06,650 --> 00:14:12,500 And the material can just be, I don't know, enum dot material and we'll just do smooth plastic. 230 00:14:13,310 --> 00:14:18,110 We want to have a default name in case for some reason a name never got passed, and the default name 231 00:14:18,110 --> 00:14:20,000 we could just set is Drink Cup. 232 00:14:21,420 --> 00:14:23,850 Um, we can set a default dispense message. 233 00:14:23,850 --> 00:14:27,000 So dispense underscore message equal to. 234 00:14:27,750 --> 00:14:29,220 Dispensing. 235 00:14:29,220 --> 00:14:30,660 This will be the default. 236 00:14:31,930 --> 00:14:33,250 Don't forget your commas. 237 00:14:34,370 --> 00:14:39,440 We can have a default consumption message when a player consumes the drink, and since they didn't pass 238 00:14:39,440 --> 00:14:42,230 anything, we'll just put like three dots because I don't know what to put there. 239 00:14:42,950 --> 00:14:48,020 We can have a default, uh, dispense sound in case one doesn't get passed. 240 00:14:48,020 --> 00:14:49,730 So that'll be sound service. 241 00:14:49,760 --> 00:14:50,570 Get the sip. 242 00:14:50,600 --> 00:14:54,200 Two nine, four sounds folder, the GUI and the dispense sound. 243 00:14:54,200 --> 00:14:58,850 And we could do the same thing for the consumption sound in case they did not pass a consume sound. 244 00:14:58,850 --> 00:15:05,210 So sound service SCP 294 sounds, and we'll just do the regular consume. 245 00:15:05,420 --> 00:15:06,740 I believe it's just called drink. 246 00:15:06,740 --> 00:15:06,980 Yeah. 247 00:15:06,980 --> 00:15:08,420 This drink sound instance. 248 00:15:08,420 --> 00:15:10,880 So these will be our defaults. 249 00:15:11,330 --> 00:15:14,510 And last but not least we'll have a default for the is empty boolean. 250 00:15:14,510 --> 00:15:16,580 And we'll just set the default to be false. 251 00:15:16,580 --> 00:15:22,130 And then we can also define a constant for a string we can attach to the name of the drink. 252 00:15:22,130 --> 00:15:28,310 And I'm going to call this drink name and set it to cup of and then a space. 253 00:15:28,310 --> 00:15:33,560 So what my plan is, is from all these pre-made drinks it's going to create a bunch of these objects. 254 00:15:33,560 --> 00:15:34,790 When I play or requests it. 255 00:15:34,790 --> 00:15:35,420 Right. 256 00:15:35,420 --> 00:15:38,930 And we want to attach this string to the name of the drink. 257 00:15:38,930 --> 00:15:40,730 So in this case it would be air. 258 00:15:40,730 --> 00:15:43,490 So we would get a cup of air in our inventory. 259 00:15:43,880 --> 00:15:44,390 All right. 260 00:15:44,390 --> 00:15:48,950 So now it's on to creating some private functions for our class one private function. 261 00:15:48,950 --> 00:15:50,810 That's going to be very important for us. 262 00:15:50,810 --> 00:15:54,320 And I'm going to call it check arg for type. 263 00:15:56,660 --> 00:16:02,540 And the purpose of this function is going to check a type to see if it is equal to another type. 264 00:16:02,540 --> 00:16:08,570 So if we have functions in here or we have our constructor or those events we're listening to, we want 265 00:16:08,570 --> 00:16:12,620 to make sure that whatever value is being passed through those functions, whatever value is being passed 266 00:16:12,620 --> 00:16:16,280 to the events, are of the correct type or of the expected type. 267 00:16:16,280 --> 00:16:19,760 And if they aren't, then we can create an error in the script. 268 00:16:19,760 --> 00:16:24,380 So the first argument to this function could be just the argument we're looking at. 269 00:16:24,380 --> 00:16:25,460 And it could be anything. 270 00:16:25,460 --> 00:16:26,660 So we'll set it to any. 271 00:16:27,110 --> 00:16:29,930 And we can say the required type is going to be a string. 272 00:16:29,930 --> 00:16:34,640 Because when we use the type of functions it's going to return a string back to us. 273 00:16:35,570 --> 00:16:42,770 So when we get this arg passed to this function, we can check if the type of this arg is equal to the 274 00:16:42,770 --> 00:16:43,910 required type. 275 00:16:44,120 --> 00:16:48,200 So if the arg is what we expect, then we can just return and end. 276 00:16:48,200 --> 00:16:49,280 We don't need to error. 277 00:16:49,520 --> 00:16:55,520 However, let's say the argument we passed is not, you know, one of the primitive data types, but 278 00:16:55,520 --> 00:16:59,990 it's one of perhaps maybe a custom type in Roblox. 279 00:16:59,990 --> 00:17:05,900 Like maybe it's a part or it's a tool, and we want to be able to make sure that whatever is being passed 280 00:17:05,900 --> 00:17:10,070 is of the class of tool, or of the class of part and so on. 281 00:17:10,460 --> 00:17:15,140 So instead, what we could do is we could create another if statement, and we could check if the type 282 00:17:15,140 --> 00:17:19,040 of this argument is equal to the custom data type of instance. 283 00:17:19,040 --> 00:17:25,970 Because when we use the type of function on parts, on unions, on perhaps these remote events, remote 284 00:17:25,970 --> 00:17:30,590 functions, whatever it is, it's not going to tell us it's a remote event or it's a remote function, 285 00:17:30,590 --> 00:17:35,810 it's just going to tell us it's an instance, and if it's an instance, then we need to check the class 286 00:17:35,810 --> 00:17:36,890 of that instance. 287 00:17:36,890 --> 00:17:42,440 So what we could do is that if the type of this argument is an instance, then we can check to see if 288 00:17:42,440 --> 00:17:44,120 the argument is of a particular class. 289 00:17:44,120 --> 00:17:46,040 Using the is a function. 290 00:17:46,760 --> 00:17:49,910 And we can pass the required type. 291 00:17:50,640 --> 00:17:52,740 And if it is, then we'll just return. 292 00:17:53,940 --> 00:18:00,360 So, for example, if the argument we get is a part and we're expecting a part, it'll check to see 293 00:18:00,360 --> 00:18:03,570 that this part is of the class part and we're good. 294 00:18:04,140 --> 00:18:08,550 Otherwise, if the argument we pass does not match the required type or the type we expect, then we 295 00:18:08,550 --> 00:18:09,630 can create an error. 296 00:18:09,630 --> 00:18:11,520 So I'll create an error message. 297 00:18:12,980 --> 00:18:20,270 And it'll be equal to a string that just says something like expected type will put that percentage 298 00:18:20,270 --> 00:18:24,650 s again, which is representing our directive here, which is going to be a string. 299 00:18:24,830 --> 00:18:27,680 And we got type percentage s. 300 00:18:27,680 --> 00:18:33,260 And a cool thing we can do with the string format function is we don't have to do string dot format. 301 00:18:33,410 --> 00:18:38,000 Instead we could actually wrap this string with parentheses. 302 00:18:38,000 --> 00:18:42,380 And we can call the format function directly on it using these two colons. 303 00:18:42,380 --> 00:18:46,910 And in here we can just pass the strings that we want to replace these two directives. 304 00:18:46,910 --> 00:18:50,540 So in this case that would be the required type. 305 00:18:50,540 --> 00:18:52,610 We expected this required type. 306 00:18:52,610 --> 00:18:57,590 But instead we got the type which is going to be type of our argument. 307 00:18:57,590 --> 00:18:59,030 So it's formatting the string. 308 00:18:59,030 --> 00:19:01,160 Let's say the required type is part. 309 00:19:01,160 --> 00:19:07,220 And the type of this argument for some reason is I don't know, a boolean for some reason. 310 00:19:07,220 --> 00:19:11,960 Then we could say expected type part got type boolean, something like that. 311 00:19:11,960 --> 00:19:12,800 Whatever. 312 00:19:12,800 --> 00:19:18,740 And then we can use the error function and just pass our error message to halt the thread of execution. 313 00:19:18,740 --> 00:19:19,490 Cool. 314 00:19:20,000 --> 00:19:26,180 Another function we'll need is for destroying a drink object once it's been consumed. 315 00:19:26,180 --> 00:19:29,780 And we'll pass self to this and we'll fill this out later. 316 00:19:30,380 --> 00:19:37,760 Um, we'll have a function for applying all of the properties of the liquid onto our cup tool. 317 00:19:37,760 --> 00:19:42,890 So I'll just call it apply properties and we'll get an instance in here. 318 00:19:42,890 --> 00:19:47,000 Say it's an instance and we'll get the properties for it. 319 00:19:47,510 --> 00:19:48,800 And this one's pretty easy. 320 00:19:48,800 --> 00:19:53,090 What we could just do is loop through every single property and value in pairs. 321 00:19:53,090 --> 00:19:54,410 Properties. 322 00:19:55,750 --> 00:19:58,480 And what we could do is just set the instance. 323 00:19:59,320 --> 00:20:00,250 Property. 324 00:20:01,010 --> 00:20:02,690 Equal to this value. 325 00:20:02,690 --> 00:20:08,420 So if it's a part and we have properties like the size or whatever, we'll set the size to that value. 326 00:20:08,450 --> 00:20:09,320 Pretty simple. 327 00:20:09,740 --> 00:20:14,030 We will need a function to listen for okay. 328 00:20:14,030 --> 00:20:15,920 So let's say we create a drink object. 329 00:20:15,920 --> 00:20:21,170 And the person who has this drink object in their inventory, let's say they die and they didn't consume 330 00:20:21,170 --> 00:20:22,070 the drink object. 331 00:20:22,070 --> 00:20:27,680 Well that means we're going to have a table taking up space and the player doesn't have the tool anymore. 332 00:20:27,680 --> 00:20:30,980 So we want to be able to listen for when that player dies and when they die. 333 00:20:30,980 --> 00:20:33,650 We can destroy this drink object and free up memory. 334 00:20:33,650 --> 00:20:36,800 So we can call this function on owner death. 335 00:20:37,410 --> 00:20:42,570 We'll pass self to it because again, self is going to represent the object or the drink object we need 336 00:20:42,570 --> 00:20:43,530 to destroy. 337 00:20:43,530 --> 00:20:45,330 And we'll fill this out in a little bit. 338 00:20:47,330 --> 00:20:48,200 Um. 339 00:20:48,200 --> 00:20:48,500 Oh. 340 00:20:48,500 --> 00:20:52,160 Another function we'll need is I plan on. 341 00:20:52,160 --> 00:20:52,700 Okay. 342 00:20:52,700 --> 00:20:55,580 So I'm going to create a name in here. 343 00:20:55,580 --> 00:20:56,810 Actually I'll do it right now. 344 00:20:57,600 --> 00:21:00,780 We'll copy this and we're going to call this random. 345 00:21:00,780 --> 00:21:04,170 So let's say a player wants to get a random drink. 346 00:21:04,170 --> 00:21:07,650 They type in random or they type in randomness. 347 00:21:07,650 --> 00:21:10,590 We want to get them a random drink in the game. 348 00:21:11,430 --> 00:21:14,190 So we can create a function for picking a random drink. 349 00:21:14,190 --> 00:21:17,190 We can call it get random drink name. 350 00:21:17,400 --> 00:21:21,180 And what we could do is we could create a table, we'll call it drinks. 351 00:21:21,360 --> 00:21:28,530 And we're just going to insert every possible drink name that is inside of the table, pre-made drinks. 352 00:21:28,530 --> 00:21:30,480 And we'll get the current drinks. 353 00:21:30,480 --> 00:21:36,360 So any drinks that are defined in this table here we're going to get the key for that particular drink. 354 00:21:36,360 --> 00:21:38,610 And we're going to put it in the drinks table. 355 00:21:39,000 --> 00:21:46,230 So we'll just do table.insert drinks and we'll do the drink name or the drink key whatever you'd like 356 00:21:46,230 --> 00:21:46,830 to call it. 357 00:21:47,450 --> 00:21:51,470 And then what we could do is we could return this table, but we're going to pick a random drink out 358 00:21:51,470 --> 00:21:51,650 of it. 359 00:21:51,650 --> 00:21:59,600 So we could do RNG mixed integer one to the max number of values inside of this drinks table. 360 00:21:59,780 --> 00:22:02,510 So if there's 50 drinks we insert 50 names in here. 361 00:22:02,510 --> 00:22:05,570 And we pick a random name out of those 50 drinks. 362 00:22:05,570 --> 00:22:12,140 And I think one more thing I want to do is I want to have a function specifically for creating drink 363 00:22:12,140 --> 00:22:12,530 objects. 364 00:22:12,530 --> 00:22:15,170 So I'll call it create drink object. 365 00:22:15,290 --> 00:22:20,750 And to this function we're going to pass a player who's going to act as the owner for the drink object. 366 00:22:20,750 --> 00:22:27,140 And we're also going to pass the name of this drink object or the key of the drink object. 367 00:22:28,140 --> 00:22:34,560 So let's say a player requests from the client to create a particular drink object that has been pre-made 368 00:22:34,560 --> 00:22:34,770 here. 369 00:22:34,770 --> 00:22:36,330 So let's say they want a cup of air. 370 00:22:36,420 --> 00:22:38,070 Then we'll use this function. 371 00:22:38,070 --> 00:22:42,360 We'll pass that player to the function and we'll pass the drink name to the function. 372 00:22:43,090 --> 00:22:48,070 And then from there we can go and create the drink using all the information in here. 373 00:22:48,770 --> 00:22:52,010 And of course that means we're going to have to set up our constructor. 374 00:22:52,010 --> 00:22:53,570 So let's go ahead and do that. 375 00:22:53,600 --> 00:22:59,840 So down here in this public function section inside of our drink table, we're going to create a function 376 00:22:59,840 --> 00:23:01,940 dot new our constructor. 377 00:23:02,210 --> 00:23:07,670 And of course this constructor requires us to pass some arguments to it. 378 00:23:07,670 --> 00:23:09,200 And that's going to be drink args. 379 00:23:09,200 --> 00:23:14,600 And it has to be of the type our custom drink properties table. 380 00:23:14,600 --> 00:23:15,590 Very simple. 381 00:23:16,070 --> 00:23:22,760 Now we're going to specifically use this constructor for creating drinks that exist in our premade drinks 382 00:23:22,760 --> 00:23:23,900 module script. 383 00:23:23,900 --> 00:23:29,540 So if we have a bunch of different drinks in here like air, honey, soda, whatever, then that means 384 00:23:29,540 --> 00:23:33,860 we're going to have to access the key for that particular drink. 385 00:23:33,860 --> 00:23:40,580 So that means when we required up here to have a pre-made key to be stored in our drink properties, 386 00:23:40,580 --> 00:23:44,870 we want to make sure that it actually exists when this constructor gets called. 387 00:23:45,230 --> 00:23:47,570 So we can use the assert function. 388 00:23:47,660 --> 00:23:53,810 And then do drink args dot premade key if premade key doesn't exist. 389 00:23:53,810 --> 00:23:59,120 If this value is false or nil, then this is going to error and we can do an error message like drink 390 00:23:59,120 --> 00:24:05,210 dot new requires original key for premade drinks. 391 00:24:05,510 --> 00:24:09,080 So if they did not supply us a key then we're not going to do anything. 392 00:24:09,080 --> 00:24:10,700 We're not going to create nothing. 393 00:24:10,760 --> 00:24:14,750 Otherwise if we're good to go then we're going to create a new table called self. 394 00:24:15,200 --> 00:24:22,220 And we're going to set the meta table of an empty table to the drink, empty the drink meta table. 395 00:24:22,220 --> 00:24:25,130 And then from this point we can set a bunch of properties in here. 396 00:24:25,130 --> 00:24:31,010 For example inside of this object maybe I want to have a cup property that's going to represent the 397 00:24:31,010 --> 00:24:31,700 tool. 398 00:24:31,700 --> 00:24:37,580 And we can do cup tool and clone it and create a new tool for this particular object. 399 00:24:37,580 --> 00:24:42,680 We can set the name for this object equal to drink args dot name. 400 00:24:43,260 --> 00:24:50,610 And if for some reason it doesn't exist, then we can use our default, which is or defaults dot name. 401 00:24:50,760 --> 00:24:52,230 We'll do the same thing for the key. 402 00:24:52,230 --> 00:24:57,540 So premade key is equal to drink args dot premade key. 403 00:24:58,110 --> 00:24:59,310 Self dot. 404 00:24:59,310 --> 00:25:06,150 The properties for the liquid is equal to drink args dot liquid properties. 405 00:25:06,150 --> 00:25:08,670 And if it doesn't exist then we'll do the defaults. 406 00:25:08,850 --> 00:25:10,050 Cut properties. 407 00:25:10,850 --> 00:25:12,770 And again, we'll just do this for every single one. 408 00:25:12,770 --> 00:25:18,380 So is empty is equal to drink args. 409 00:25:19,670 --> 00:25:20,990 That is empty. 410 00:25:22,600 --> 00:25:24,670 Or defaults. 411 00:25:24,700 --> 00:25:28,360 Dot is empty, so if it's true, we'll set it to true. 412 00:25:28,360 --> 00:25:30,490 If it's false, then it'll just stay false. 413 00:25:31,830 --> 00:25:37,230 Um, we're going to have a property in here that's going to act as a debounce for this particular object. 414 00:25:37,230 --> 00:25:40,530 So we'll call it effects debounce and we'll set it to false. 415 00:25:40,530 --> 00:25:44,910 And this is going to be for the drink functions. 416 00:25:44,910 --> 00:25:49,440 So let's say this drink had a particular function we needed to execute on the server or on the client. 417 00:25:49,440 --> 00:25:54,090 Then we want to make sure we don't execute it multiple times by keeping track of this debounce. 418 00:25:54,420 --> 00:26:00,690 And then some other things we could set is like the dispense message, just set it equal to drink args 419 00:26:00,690 --> 00:26:08,910 dot dispense message or defaults, not debug defaults dot dispense message. 420 00:26:08,910 --> 00:26:11,400 And again we're just going to keep going on and on. 421 00:26:20,680 --> 00:26:26,110 And can see how having a custom type makes it really easy for us to see the particular different properties 422 00:26:26,110 --> 00:26:31,450 we need for our drink arguments, so we can just hit dot, index it, and we can see all the properties 423 00:26:31,450 --> 00:26:32,740 we have for our particular drink. 424 00:26:32,740 --> 00:26:34,300 So it's again pretty useful. 425 00:26:35,350 --> 00:26:38,050 So I'll have a consume sound or the default. 426 00:26:42,280 --> 00:26:48,040 And then last but not least, we need to have a custom ID for our new drink object. 427 00:26:48,040 --> 00:26:52,960 So we'll call it.id and it's going to be equal to the Http service. 428 00:26:52,960 --> 00:26:56,590 And there's a function in there called generate g uid. 429 00:26:56,860 --> 00:27:00,970 And it generates a uuid g uid random string. 430 00:27:00,970 --> 00:27:03,880 So basically it generates a string that looks like this. 431 00:27:03,880 --> 00:27:06,010 It's a bunch of numbers letters and dashes. 432 00:27:06,010 --> 00:27:09,820 And we can use this to, you know, find a particular drink with this ID. 433 00:27:10,210 --> 00:27:12,340 And these IDs are completely random. 434 00:27:12,340 --> 00:27:18,220 The chance of an object having the same ID as another is basically zero, so you don't have to worry 435 00:27:18,220 --> 00:27:18,790 about it. 436 00:27:18,970 --> 00:27:26,740 So now that we have our custom ID set for our drink, I want to be able to set the tool to have an attribute 437 00:27:26,740 --> 00:27:28,090 that's equal to the id. 438 00:27:28,090 --> 00:27:34,510 So on the cup tool itself we're going to set an attribute called drink ID and it's going to be equal 439 00:27:34,510 --> 00:27:35,590 to self.id. 440 00:27:36,310 --> 00:27:41,530 So that way when a player gets a drink cup and it gets put in their inventory, the player can go, 441 00:27:41,530 --> 00:27:43,600 hey, I've got this new drink cup. 442 00:27:43,600 --> 00:27:48,970 I want to request the drink object with this drink ID so I can get access to, you know, like the sounds 443 00:27:48,970 --> 00:27:51,520 and the messages that I need to display on the screen. 444 00:27:52,120 --> 00:27:54,100 And then we could also set the name for the cup. 445 00:27:54,100 --> 00:28:00,820 So cup dot name, we'll set it equal to I guess we'll just do self dot name for now, because what we'll 446 00:28:00,820 --> 00:28:06,280 do is we'll set the drink args name to be concatenated with the string up here later. 447 00:28:06,280 --> 00:28:08,650 So we'll set the cup name equal to the name. 448 00:28:08,770 --> 00:28:13,870 And then we also need to apply all those properties to our particular cup tool. 449 00:28:13,870 --> 00:28:18,580 So we could call that apply properties function on the self dot cup. 450 00:28:18,580 --> 00:28:22,240 And inside of our tool there's a part that represents the liquid. 451 00:28:22,240 --> 00:28:23,980 So dot liquid. 452 00:28:25,410 --> 00:28:29,370 And we need to apply all of these self dot liquid properties. 453 00:28:29,980 --> 00:28:35,170 So now that we've got basically everything we needed set up inside of our drink object, we can insert 454 00:28:35,170 --> 00:28:37,750 it into the current drinks table. 455 00:28:37,750 --> 00:28:41,710 So that way we can access it later on or destroy it if we need to. 456 00:28:42,770 --> 00:28:46,820 And we can check to see if drink args not owner was passed. 457 00:28:46,820 --> 00:28:49,700 So do we get an owner pass to this function? 458 00:28:49,700 --> 00:28:54,020 If we did then we can set the owner for this particular drink. 459 00:28:54,020 --> 00:28:56,900 And actually we'll create a function for that in a little bit as well. 460 00:28:56,900 --> 00:28:58,940 So I'm going to leave this blank for now. 461 00:28:59,150 --> 00:29:06,080 But after we have set all of this stuff up for our object or our table, then we can just return it 462 00:29:06,080 --> 00:29:07,250 at the very end. 463 00:29:07,460 --> 00:29:14,180 So now we've got our custom drink object that contains the tool, the name, the effects, the sounds, 464 00:29:14,180 --> 00:29:17,690 the messages and the custom ID and all that good stuff. 465 00:29:17,690 --> 00:29:19,220 So now let's create some other functions. 466 00:29:19,220 --> 00:29:22,100 I want to exist inside of my drink table. 467 00:29:22,520 --> 00:29:27,830 So one function I want is to get all of the drinks that are in my game. 468 00:29:27,830 --> 00:29:29,180 So we'll call it get drinks. 469 00:29:29,180 --> 00:29:31,910 And all it's going to do is return the current drinks. 470 00:29:31,910 --> 00:29:39,770 I also want to have a function for getting a particular drink object based off the ID that is passed 471 00:29:39,770 --> 00:29:42,020 to the function, so we can call this drink. 472 00:29:42,020 --> 00:29:48,170 Get object from ID, and we need to pass an ID to this function, which is a string. 473 00:29:48,500 --> 00:29:51,380 And for this function in particular we can check the arg. 474 00:29:51,380 --> 00:29:55,940 For type this id we want to make sure it is of the type string. 475 00:29:55,940 --> 00:29:58,310 Otherwise if it isn't, we're just going to error. 476 00:29:58,460 --> 00:30:05,000 Otherwise we can just loop through every single drink object that is inside of our current drinks table. 477 00:30:05,870 --> 00:30:12,290 And what we could do is we could check if this drink this particular drink object.id is equal to the 478 00:30:12,290 --> 00:30:13,580 ID passed to this function. 479 00:30:13,580 --> 00:30:17,330 And if it is, we'll return this drink and that's it. 480 00:30:17,330 --> 00:30:20,690 If we didn't find anything then this function will return nothing. 481 00:30:21,320 --> 00:30:22,640 So again this is important. 482 00:30:22,640 --> 00:30:24,110 Why we have this ID here. 483 00:30:24,110 --> 00:30:27,410 That way the client can get a particular drink based on the id. 484 00:30:27,980 --> 00:30:33,920 Now let's create some functions for the drink meta table or specifically for the drink object itself, 485 00:30:33,920 --> 00:30:35,720 not part of the class. 486 00:30:35,840 --> 00:30:42,470 One function we want to have for the drink meta table is to be able to set the owner of our drink. 487 00:30:43,400 --> 00:30:46,400 And this owner is going to be, of course, a player. 488 00:30:46,840 --> 00:30:50,350 And again we can use that check arg for type function. 489 00:30:50,350 --> 00:30:57,610 We can check this player or this owner that gets passed to this function to make sure it is of the type 490 00:30:57,610 --> 00:31:00,820 player or this instances of the class player. 491 00:31:00,820 --> 00:31:02,590 And we'll just pass player here. 492 00:31:03,400 --> 00:31:05,020 And if it is, we can do self. 493 00:31:05,020 --> 00:31:07,960 Dot owner is equal to the owner. 494 00:31:07,960 --> 00:31:12,700 And remember self is referring to the object that gets created from our constructor. 495 00:31:12,700 --> 00:31:15,940 And there is an owner property in there I believe. 496 00:31:15,940 --> 00:31:17,620 Um, or actually we didn't set it yet. 497 00:31:18,220 --> 00:31:19,630 So I'll put an else statement here. 498 00:31:19,630 --> 00:31:22,300 We'll just do self dot owner is equal to nil. 499 00:31:23,200 --> 00:31:26,050 But basically we'll set an owner property in here. 500 00:31:26,830 --> 00:31:32,860 And now that means because this cup now has an owner we want to be able to listen to when this owner 501 00:31:32,860 --> 00:31:33,400 dies. 502 00:31:33,400 --> 00:31:35,530 So let's say they have the drink in their inventory. 503 00:31:35,530 --> 00:31:37,210 They never drink it but they die. 504 00:31:37,210 --> 00:31:41,380 We want to be able to delete that cup object so we can free up memory. 505 00:31:41,380 --> 00:31:48,610 So we can do self dot owner get their character and get the humanoid in their character and listen to 506 00:31:48,610 --> 00:31:49,720 the died event. 507 00:31:49,720 --> 00:31:54,670 So when that player dies we can connect a lambda function to it. 508 00:31:55,450 --> 00:32:01,690 And we'll call that on owner death function I talked about earlier and pass this, uh, drink object 509 00:32:01,690 --> 00:32:03,340 in particular to this function. 510 00:32:05,220 --> 00:32:11,460 And the last but not least, we need to set the parent of this particular cup tool to that owner or 511 00:32:11,460 --> 00:32:12,750 that player's backpack. 512 00:32:12,750 --> 00:32:14,460 So owner backpack. 513 00:32:14,580 --> 00:32:19,380 Now we're going to need a function for consuming the drink. 514 00:32:19,380 --> 00:32:23,010 So drink meta table consume. 515 00:32:23,160 --> 00:32:28,320 And this is going to be on the server only I plan to have a consume function on the client and on the 516 00:32:28,320 --> 00:32:29,070 server. 517 00:32:29,070 --> 00:32:34,830 So when the player consumes it on their end, they're going to apply any of the client side effects 518 00:32:34,830 --> 00:32:38,940 that may exist in the pre-made drink functions, uh, module script. 519 00:32:38,940 --> 00:32:42,960 And of course, they're also going to display the GUI message on their screen. 520 00:32:42,960 --> 00:32:49,470 And all I want the server to do is set the transparency of the liquid to be invisible, so it makes 521 00:32:49,470 --> 00:32:51,420 it look like we drank out of the cup. 522 00:32:51,420 --> 00:32:57,030 So self dot cup dot liquid dot transparency equal to one. 523 00:32:57,030 --> 00:32:58,710 That's all I want this function to do. 524 00:32:58,710 --> 00:33:04,230 Last but not least, we need to have a function for all of our drink objects to be able to destroy them. 525 00:33:04,230 --> 00:33:08,100 So we can call this drink empty destroy. 526 00:33:08,130 --> 00:33:10,560 We want to be able to destroy this drink object. 527 00:33:11,260 --> 00:33:16,420 And since this function is going to be called from the server, we need to let the player know that 528 00:33:16,420 --> 00:33:21,910 they need to destroy that object on their end as well, because there's going to be two separate objects, 529 00:33:21,910 --> 00:33:24,970 one that exists on the server and one that exists on the client. 530 00:33:24,970 --> 00:33:27,700 So we need the client to destroy their drink object as well. 531 00:33:27,700 --> 00:33:29,950 And that is what the communication event is for. 532 00:33:29,950 --> 00:33:33,490 So comms event fire client. 533 00:33:33,790 --> 00:33:37,600 And we're going to fire to the self dot owner. 534 00:33:38,340 --> 00:33:42,480 And we'll tell them to destroy drink object. 535 00:33:42,480 --> 00:33:45,240 This is going to be the action we want them to do. 536 00:33:45,240 --> 00:33:47,820 Which drink object we want them to destroy? 537 00:33:47,820 --> 00:33:51,510 Well, we can tell them by using the self.id. 538 00:33:51,840 --> 00:33:57,060 So we're telling the client, hey, look for an object on your end that has this ID and we want you 539 00:33:57,060 --> 00:33:58,170 to destroy it. 540 00:33:59,250 --> 00:34:04,170 And then from that point, we also need to destroy the drink object on the server as well. 541 00:34:04,170 --> 00:34:08,640 So we can call that destroy drink object function and pass the object to it. 542 00:34:10,560 --> 00:34:17,550 And then I guess I can have this function return true to make sure that, you know, the object got 543 00:34:17,550 --> 00:34:18,510 destroyed. 544 00:34:18,810 --> 00:34:22,050 So let's go ahead and fill out this destroyed drink object function. 545 00:34:22,320 --> 00:34:27,000 We'll scroll back up here to the private functions that exist in this class. 546 00:34:27,450 --> 00:34:33,480 So what I want to do when I want to destroy a particular drink object, well first I need to destroy 547 00:34:33,480 --> 00:34:34,020 the tool. 548 00:34:34,020 --> 00:34:37,320 So self dot cup will destroy that tool. 549 00:34:38,640 --> 00:34:46,740 And then what we need to do is we need to find this particular object inside of our current drinks table. 550 00:34:46,860 --> 00:34:50,880 So we'll get the index by using the table dot find function. 551 00:34:50,880 --> 00:34:55,860 So inside of the current drinks table we're going to look for this particular object. 552 00:34:55,860 --> 00:34:58,740 And it's going to tell us at what index it resides. 553 00:34:58,740 --> 00:35:01,350 And that means we can remove it from our table. 554 00:35:01,350 --> 00:35:03,720 So current drinks remove it at that index. 555 00:35:04,920 --> 00:35:08,580 And then we need to set the meta table for this object to nil. 556 00:35:08,580 --> 00:35:10,770 So we're basically getting rid of the meta table. 557 00:35:10,770 --> 00:35:16,620 And then we're going to destroy the table by clearing all the contents using the table dot clear function. 558 00:35:16,620 --> 00:35:21,750 And it clears out every single property key value pair whatever we had in the table. 559 00:35:21,750 --> 00:35:24,690 So all this stuff right here, it all gets destroyed. 560 00:35:26,000 --> 00:35:29,390 And then we can just basically, I guess, set self to nil. 561 00:35:29,390 --> 00:35:33,530 But since it's going to be an empty table, it doesn't really matter that much. 562 00:35:33,530 --> 00:35:37,010 And this is basically how we destroy our drink object. 563 00:35:37,580 --> 00:35:42,590 And we're going to call this function again from the destroy function. 564 00:35:42,590 --> 00:35:44,570 That's part of the drink meta table. 565 00:35:45,540 --> 00:35:50,460 And actually what we could do here, just in case this particular drink doesn't have an owner. 566 00:35:51,300 --> 00:35:53,280 If self dot owner. 567 00:35:53,280 --> 00:35:55,860 So if there's an owner then we'll fire the event. 568 00:35:55,860 --> 00:35:58,680 Otherwise we'll just destroy it on the server end. 569 00:35:59,400 --> 00:36:05,520 Now, of course, that means we're going to need some event handlers specifically for our communication 570 00:36:05,520 --> 00:36:08,580 event and for our request remote function. 571 00:36:09,320 --> 00:36:15,410 So let's fill out the request event or the remote function first. 572 00:36:16,100 --> 00:36:21,710 So we're going to access the on server invoke property and set it equal to a Lambda function. 573 00:36:22,790 --> 00:36:29,300 Now, what I want the client to pass to the server is the action the client wants the server to do, 574 00:36:29,300 --> 00:36:33,260 and any other arguments that needs to be supplied with that action. 575 00:36:33,290 --> 00:36:38,900 So first off, the on server invoke when it gets called will automatically pass the player. 576 00:36:39,380 --> 00:36:45,080 So we get the player, we get the action they want us to do, which should be a string, and we just 577 00:36:45,080 --> 00:36:49,670 get some extra arguments or a table containing all the other arguments we want to do for this particular 578 00:36:49,670 --> 00:36:50,360 action. 579 00:36:50,750 --> 00:36:56,330 And of course, we're going to have to verify the information from the client so we can check ARG for 580 00:36:56,330 --> 00:36:59,540 type of action to make sure it's a string. 581 00:37:00,230 --> 00:37:07,010 We can check arg for type of the arguments, and we'll make sure it's a table containing, you know, 582 00:37:07,010 --> 00:37:08,510 arguments and whatnot. 583 00:37:09,320 --> 00:37:17,060 And once we verify that's all good, then we can do if action is equal to request drink object. 584 00:37:18,630 --> 00:37:25,050 Then what we could do is we could get that object. 585 00:37:26,420 --> 00:37:34,520 From its ID, so when the player or the client wants to request a drink object because they got a tool 586 00:37:34,520 --> 00:37:38,150 set in their inventory, they're going to go ahead and request it. 587 00:37:38,150 --> 00:37:40,010 And that'll be in the args table. 588 00:37:40,010 --> 00:37:42,140 And we'll say that's going to be the first argument. 589 00:37:42,740 --> 00:37:45,500 So args one is the ID. 590 00:37:45,620 --> 00:37:49,130 So we're going to get the drink object from this ID. 591 00:37:50,860 --> 00:37:56,800 If we didn't get an object, then we'll just return a false to the player and we'll give them a message 592 00:37:56,800 --> 00:37:59,380 like drink object with ID. 593 00:37:59,650 --> 00:38:03,490 We could do dot dot dot args one. 594 00:38:04,510 --> 00:38:06,010 Does not exist. 595 00:38:06,010 --> 00:38:09,700 So whatever drink object they requested with this ID doesn't exist. 596 00:38:09,880 --> 00:38:14,620 The next thing we need to do is we need to make sure or verify that they're the owner of this drink 597 00:38:14,620 --> 00:38:15,430 object. 598 00:38:15,580 --> 00:38:18,280 So if object dot owner. 599 00:38:19,090 --> 00:38:21,460 Is not equal to this particular player. 600 00:38:21,460 --> 00:38:28,960 Then again we're going to return false and we're going to tell the client you do not own this object. 601 00:38:29,800 --> 00:38:31,120 They can't have it. 602 00:38:31,120 --> 00:38:36,460 Otherwise, if all checks out good, we can return true to the client to say everything went well and 603 00:38:36,460 --> 00:38:38,530 we can return that object back to them. 604 00:38:38,530 --> 00:38:44,140 Now you need to understand there is a limitation with, uh, remote events and remote functions. 605 00:38:44,140 --> 00:38:51,640 And when we pass tables to a client or a client passes a table to the server, any meta table that is 606 00:38:51,640 --> 00:38:55,090 attached to that particular object gets destroyed. 607 00:38:55,090 --> 00:38:59,470 So you won't be able to have an object with this meta table attached to it. 608 00:38:59,470 --> 00:39:04,450 And for our purposes, that's going to be totally fine, because what we're going to do on the client 609 00:39:04,450 --> 00:39:09,250 is that when they get this table, which is just going to contain all these properties, we're going 610 00:39:09,250 --> 00:39:13,720 to attach the meta table that exists within the drink class on the client instead. 611 00:39:13,720 --> 00:39:17,560 And that meta table contains all the client related functions. 612 00:39:17,560 --> 00:39:19,000 So it works out well for us. 613 00:39:19,000 --> 00:39:22,000 We don't have to worry about the meta table being lost. 614 00:39:22,000 --> 00:39:28,360 Now some other actions I want to put in here that the client should be able to do is to check to see 615 00:39:28,360 --> 00:39:29,710 if a drink exists. 616 00:39:29,710 --> 00:39:33,490 So let's say they're in the GUI and they're punching in the name of a drink. 617 00:39:33,490 --> 00:39:36,100 And that drink for some reason doesn't exist. 618 00:39:36,100 --> 00:39:38,680 Well, they need to check to see if it exists in the first place. 619 00:39:38,680 --> 00:39:41,590 So that's what they can use this remote function for. 620 00:39:41,590 --> 00:39:44,680 They can request an action like check for drink. 621 00:39:45,740 --> 00:39:55,880 And what we'll do is we're going to loop through every single, uh, key and possible names that is 622 00:39:55,880 --> 00:39:58,070 inside of the table. 623 00:39:58,640 --> 00:40:04,580 Pre-made drinks dot current names or not current drinks, current names. 624 00:40:05,330 --> 00:40:08,390 So let's say they input a name like vacuum. 625 00:40:08,390 --> 00:40:13,640 What we're going to loop through every single key value pair in here we're going to see if a string 626 00:40:13,640 --> 00:40:14,750 of vacuum exists. 627 00:40:14,750 --> 00:40:18,200 So it'll look through here and it'll say hey vacuum exists. 628 00:40:18,200 --> 00:40:23,420 We'll get that key and we'll tell you, hey, this drink exists and all will be fine. 629 00:40:24,610 --> 00:40:28,120 So we're going to loop through all of those and we're going to check. 630 00:40:28,980 --> 00:40:35,100 If not table dot find inside of all possible names or possible names. 631 00:40:36,150 --> 00:40:37,920 ARGs and we'll do args one. 632 00:40:37,920 --> 00:40:43,410 So again args one is the name for the drink. 633 00:40:43,990 --> 00:40:48,520 So if we couldn't find this drink in this first iteration of the loop, then we're just going to continue 634 00:40:48,520 --> 00:40:49,270 looping. 635 00:40:51,300 --> 00:40:54,120 Otherwise, if we do find it, we can return true. 636 00:40:54,780 --> 00:40:58,500 We can return to them the key for this particular drink. 637 00:40:58,680 --> 00:41:00,630 And then we can also return to them. 638 00:41:00,630 --> 00:41:05,850 Pre-made drinks dot current drinks and get the. 639 00:41:06,440 --> 00:41:08,600 Properties for this particular drink. 640 00:41:08,600 --> 00:41:11,630 So we're telling the client, hey, this drink exists. 641 00:41:11,630 --> 00:41:16,010 Here is all of the properties for the drink and the key as well. 642 00:41:16,010 --> 00:41:19,280 So you can, you know, go ahead and request to create a new drink. 643 00:41:19,850 --> 00:41:22,370 Another action I want the client to be able to do. 644 00:41:23,420 --> 00:41:26,870 Is to create a new drink object and get it. 645 00:41:26,870 --> 00:41:29,480 So they're requesting it from the client. 646 00:41:29,480 --> 00:41:33,320 So we'll call it create and get drink object. 647 00:41:34,490 --> 00:41:40,430 And the only purpose of this is to return whatever gets returned from the create drink object function, 648 00:41:40,550 --> 00:41:48,410 and we want to pass the player and args one and args one is going to of course. 649 00:41:49,420 --> 00:41:55,210 Represent the key, so args one is the key for the pre-made drink. 650 00:41:57,840 --> 00:42:03,690 And then one more action we want to do is to destroy a drink object. 651 00:42:04,430 --> 00:42:09,980 So let's say the client on their end wants to destroy a particular drink object they have. 652 00:42:09,980 --> 00:42:14,030 Then what we could do is we could look for this object. 653 00:42:14,030 --> 00:42:17,810 So args one can be the id. 654 00:42:17,810 --> 00:42:20,630 So is the id of the object. 655 00:42:21,980 --> 00:42:27,890 We'll create a variable and we'll call the get object from id function. 656 00:42:27,890 --> 00:42:30,800 That's part of our class and pass args one. 657 00:42:32,350 --> 00:42:36,040 If there is no object, then we're going to return false. 658 00:42:36,580 --> 00:42:38,620 Object does not exist. 659 00:42:41,120 --> 00:42:48,830 If the owner of this object is not equal to the player, then we're going to return false as well, 660 00:42:48,860 --> 00:42:53,120 because we don't want exploiters to be able to destroy other people's drinks. 661 00:42:53,890 --> 00:42:57,880 So we could say you do not own this object. 662 00:43:00,040 --> 00:43:05,920 Otherwise, if everything checks out, we can destroy the drink object on the server using the destroy 663 00:43:05,920 --> 00:43:11,200 drink object function, and we'll return true to say, hey, we successfully destroyed the object. 664 00:43:11,650 --> 00:43:15,580 Otherwise, let's say the client passed an action that didn't match any of these that I defined. 665 00:43:15,580 --> 00:43:15,820 Here. 666 00:43:15,820 --> 00:43:25,150 We can just return false at the very end and just say requested action did not match possible actions. 667 00:43:25,660 --> 00:43:28,390 And that's all the client needs to know from this function. 668 00:43:28,870 --> 00:43:32,440 Now let's go ahead and listen to the comms event. 669 00:43:32,440 --> 00:43:34,660 So on server event. 670 00:43:36,110 --> 00:43:41,630 When this remote event gets fired from the client, it's going to pass the player that fired the remote. 671 00:43:42,110 --> 00:43:44,450 Um, again, we'll want to have an action. 672 00:43:44,450 --> 00:43:50,120 So string and we'll have arguments from the client. 673 00:43:50,210 --> 00:43:54,740 And again we'll check the arguments action to make sure it's a string. 674 00:43:56,320 --> 00:44:01,570 And we'll make sure the argument they passed is a table containing some arguments. 675 00:44:01,930 --> 00:44:07,270 So we can have an action for, let's say, the player verified that a drink existed. 676 00:44:07,270 --> 00:44:12,790 Then they want to go ahead and create a drink object and get that drink object in their inventory. 677 00:44:12,790 --> 00:44:17,350 So we can have an action called create drink object. 678 00:44:19,880 --> 00:44:22,310 And we can create the string object. 679 00:44:23,930 --> 00:44:25,190 Passed to the player. 680 00:44:26,160 --> 00:44:31,560 And args, one is going to represent the key for this particular drink object. 681 00:44:31,560 --> 00:44:35,460 So args one is the key for the pre-made drink. 682 00:44:37,090 --> 00:44:38,680 We're going to have another action. 683 00:44:39,640 --> 00:44:42,610 Let's say this action is, oh, I know what to do. 684 00:44:42,640 --> 00:44:44,500 Drink effects. 685 00:44:44,590 --> 00:44:51,610 So let's say we have a function for this drink and they consume the drink. 686 00:44:51,850 --> 00:44:54,520 And let's say this drink also had some side effects. 687 00:44:54,520 --> 00:45:00,430 So like maybe they drink it and they get health reduced or they change color or whatever the case may 688 00:45:00,430 --> 00:45:00,700 be. 689 00:45:00,730 --> 00:45:05,770 We want it to be visible to other players, so we have to do it on the server as well. 690 00:45:06,310 --> 00:45:07,180 So. 691 00:45:07,740 --> 00:45:11,970 We can check to see if they have a particular object they're requesting. 692 00:45:12,000 --> 00:45:17,670 So args one can be the id, so is the ID for the drink. 693 00:45:17,670 --> 00:45:21,030 Because we need to verify that this drink actually has a function. 694 00:45:22,200 --> 00:45:27,630 So we can do drink get object from id and we'll pass args one. 695 00:45:29,360 --> 00:45:32,480 If there is no objects, then we'll just return. 696 00:45:34,380 --> 00:45:38,790 Um, then we can check to see if a player actually has this tool in their inventory. 697 00:45:38,790 --> 00:45:39,780 So if player. 698 00:45:40,670 --> 00:45:44,810 We're going to find first child inside of their backpack. 699 00:45:45,810 --> 00:45:48,570 To see if it's equal to Objectname. 700 00:45:48,600 --> 00:45:51,630 If it doesn't exist in their backpack, then we'll check the character. 701 00:45:51,630 --> 00:45:54,960 So player dot character find first child. 702 00:45:55,940 --> 00:45:57,110 Objectname. 703 00:46:00,290 --> 00:46:02,360 If they don't have this tool for some reason. 704 00:46:02,360 --> 00:46:03,740 Again, we'll just go into return. 705 00:46:03,740 --> 00:46:05,690 We don't want to apply any effects. 706 00:46:05,720 --> 00:46:12,710 Otherwise if everything checks out then we need to check the object dot effects Debounce. 707 00:46:12,710 --> 00:46:14,480 Remember that effects Debounce we made. 708 00:46:14,480 --> 00:46:21,620 We don't want to apply a server side effects more than once, so if it's already set to true then we're 709 00:46:21,620 --> 00:46:22,520 going to return. 710 00:46:22,520 --> 00:46:26,780 Otherwise we're going to set it to true so we can only execute it once. 711 00:46:27,020 --> 00:46:31,340 And then from this point we can access that drink functions module. 712 00:46:32,190 --> 00:46:40,380 And what I could do inside of the pre-made drink functions is I'll just fill this out real quick. 713 00:46:42,890 --> 00:46:45,560 We can have a section in the module scripts. 714 00:46:46,560 --> 00:46:51,210 We'll call it something like, uh, current functions. 715 00:46:51,630 --> 00:46:55,860 It's going to be a table and it's going to store the key for a particular drink. 716 00:46:55,860 --> 00:46:57,060 So let's say air. 717 00:46:57,880 --> 00:47:02,140 And we can set it equal to, I'd say, a table. 718 00:47:02,350 --> 00:47:05,500 We can create a key value pair in this table we'll call it handler. 719 00:47:05,500 --> 00:47:07,630 And it's going to be equal to a function. 720 00:47:07,750 --> 00:47:11,770 And what we want to do is we want to execute this function for this particular drink. 721 00:47:11,770 --> 00:47:16,690 If it has server side effects or if it has client side effects, then the client will do that on their 722 00:47:16,690 --> 00:47:17,140 end. 723 00:47:17,560 --> 00:47:21,610 But if it does have server side effects, we want the server to execute as well. 724 00:47:24,120 --> 00:47:28,230 So we can access the current functions. 725 00:47:28,260 --> 00:47:29,910 Current functions. 726 00:47:30,150 --> 00:47:35,730 This table here, and I'll make sure to return it at the end here to make this more clear. 727 00:47:36,660 --> 00:47:43,680 So we get the current functions table, and we check to see if the key exists for this particular drink. 728 00:47:43,680 --> 00:47:45,750 So object dot premade key. 729 00:47:45,780 --> 00:47:49,740 It's very important why we store this key to verify if there's any functions. 730 00:47:49,740 --> 00:47:54,120 If there is then we can call the handler function that exists within the table attached to it. 731 00:47:56,230 --> 00:47:57,310 So. 732 00:47:58,160 --> 00:48:01,550 If this key exists in our current functions table. 733 00:48:01,550 --> 00:48:03,380 So there's a function for this drink. 734 00:48:04,140 --> 00:48:06,690 Then we can just copy this. 735 00:48:07,480 --> 00:48:10,120 And then call the handler function. 736 00:48:10,540 --> 00:48:14,770 And what we could pass to the handler function is the player. 737 00:48:15,780 --> 00:48:22,290 That requested the server side effects to be applied, as well as the object itself to keep track of 738 00:48:22,290 --> 00:48:24,330 maybe anything else we want to do in the function. 739 00:48:24,330 --> 00:48:31,680 So that means that any function that gets called here will have a player object, and it will have the 740 00:48:31,680 --> 00:48:36,660 object itself or the drink object, and we'll just call it drink obj drink object. 741 00:48:37,950 --> 00:48:38,760 All right, hang in there. 742 00:48:38,760 --> 00:48:41,400 We're almost done with this server side class. 743 00:48:42,210 --> 00:48:50,490 Another action I want the client to be able to request through this event is to consume the drink. 744 00:48:50,490 --> 00:48:55,950 So when they consume the drink on their end, we also want to consume the drink on the server and make 745 00:48:55,950 --> 00:48:57,180 the liquid disappear. 746 00:48:58,360 --> 00:48:59,470 So again. 747 00:49:00,480 --> 00:49:00,990 ARGs. 748 00:49:00,990 --> 00:49:04,080 One is the ID for the drink. 749 00:49:05,010 --> 00:49:06,510 Local object. 750 00:49:06,660 --> 00:49:11,340 We're going to again use the get object from id function and pass args one. 751 00:49:12,880 --> 00:49:16,450 If not object, then we're just going to return. 752 00:49:16,450 --> 00:49:19,780 If it does exist, we need to verify that they're the owner. 753 00:49:19,990 --> 00:49:25,090 If not, object dot owner is equal to this player, then we'll return. 754 00:49:26,570 --> 00:49:31,040 Otherwise we can consume the drink. 755 00:49:31,040 --> 00:49:32,810 And actually this not is redundant. 756 00:49:32,810 --> 00:49:34,400 We actually just do. 757 00:49:34,990 --> 00:49:36,100 Tilde equals. 758 00:49:36,100 --> 00:49:39,490 So if the owner does not equal to the player, then we return as well. 759 00:49:41,430 --> 00:49:44,700 And I'll make sure to return this drink table at the end of the module script. 760 00:49:44,700 --> 00:49:48,660 But there is a couple more private functions we need to fill out. 761 00:49:48,660 --> 00:49:50,160 Yes, these two right here. 762 00:49:51,120 --> 00:49:57,390 So what do we want to happen when the player or the owner of this particular object dies and they didn't 763 00:49:57,390 --> 00:49:58,590 consume the drink? 764 00:49:58,830 --> 00:50:03,960 Well, what we want to happen when the player dies is we want to destroy the drink object, right? 765 00:50:03,960 --> 00:50:06,690 So we can just do self destroy. 766 00:50:07,200 --> 00:50:09,780 We destroy the drink object on the server. 767 00:50:09,780 --> 00:50:13,230 And again when we call this function, let me scroll down to it. 768 00:50:13,230 --> 00:50:17,880 It'll also tell the client to destroy it on their end as well. 769 00:50:18,000 --> 00:50:25,410 Now let's go ahead and fill out the create drink object function which we use down here and right here. 770 00:50:25,500 --> 00:50:30,870 So when the player wants to create a pre-made drink that exists inside of this table, using all of 771 00:50:30,870 --> 00:50:38,160 these properties, we're going to use this function to fill out our custom drink properties type here 772 00:50:38,160 --> 00:50:40,920 that needs to be passed to our constructor. 773 00:50:41,660 --> 00:50:42,470 So. 774 00:50:44,260 --> 00:50:49,120 What we're going to do is we're going to get the information for this drink, which exists in pre-made 775 00:50:49,120 --> 00:50:50,020 drinks. 776 00:50:50,290 --> 00:50:51,310 Current drinks. 777 00:50:51,310 --> 00:50:58,240 And we get the drink name or the key for this particular drink. 778 00:50:58,920 --> 00:51:07,050 Now, if this drink name is random or the key is random, that means we want to get a random drink instead. 779 00:51:07,050 --> 00:51:10,080 So we could we could do. 780 00:51:10,080 --> 00:51:12,930 Name is equal to get random drink name. 781 00:51:12,930 --> 00:51:14,400 Remember this function we made? 782 00:51:14,820 --> 00:51:18,900 We loop through all of the current drinks and get a random name or a random key. 783 00:51:18,990 --> 00:51:25,500 And from that point we could just set drink info equal to pre-made drinks dot current drinks. 784 00:51:26,490 --> 00:51:28,170 With this particular name. 785 00:51:28,170 --> 00:51:30,150 So we're just picking a random drink. 786 00:51:31,710 --> 00:51:37,410 Otherwise, if there is no drink info, basically the string they pass doesn't exist, then we're just 787 00:51:37,410 --> 00:51:40,710 going to return and we just do return false. 788 00:51:40,830 --> 00:51:44,280 Specifically for our. 789 00:51:45,060 --> 00:51:46,740 On server invoke function here. 790 00:51:46,740 --> 00:51:49,470 If we ever need to use it, we'll just return false. 791 00:51:53,160 --> 00:51:53,670 Otherwise. 792 00:51:53,670 --> 00:51:56,940 If all checks out, we need to create a name for the tool. 793 00:51:56,940 --> 00:51:59,100 So it'll be called tool name. 794 00:51:59,220 --> 00:52:03,060 It's going to be equal to our drink underscore name which is cup of. 795 00:52:03,060 --> 00:52:06,000 And we're going to concatenate it with the drink info. 796 00:52:07,080 --> 00:52:08,400 Dot. 797 00:52:08,430 --> 00:52:11,520 Um, I believe it is cup name, right? 798 00:52:12,150 --> 00:52:12,600 Yeah. 799 00:52:12,600 --> 00:52:13,290 Cup name. 800 00:52:13,290 --> 00:52:16,500 So if we get past air, it's going to be cup of Air. 801 00:52:17,450 --> 00:52:22,400 Now, the next thing I want to do is I want to make sure a player doesn't get duplicate drinks. 802 00:52:22,400 --> 00:52:27,020 So, for example, I don't want them to have more of one drink of a particular type. 803 00:52:27,020 --> 00:52:32,870 So I don't want them to have more than one cup of air, or more of one cup of juice or whatever it is. 804 00:52:32,870 --> 00:52:39,590 So we can check to see if the player already has this drink by again doing player dot backpack find 805 00:52:39,590 --> 00:52:40,310 first child. 806 00:52:40,310 --> 00:52:45,620 We're going to check to see if this tool exists in their backpack, or if this tool exists on their 807 00:52:45,620 --> 00:52:47,540 character, meaning they have it equipped. 808 00:52:50,050 --> 00:52:51,820 If they do have this tool. 809 00:52:53,420 --> 00:52:56,060 And we want to make sure it is a tool. 810 00:52:56,060 --> 00:52:58,790 So they have this particular tool on them. 811 00:52:58,880 --> 00:53:01,010 Then we're going to return false. 812 00:53:01,010 --> 00:53:03,560 And we don't want any duplicates. 813 00:53:03,590 --> 00:53:05,600 No duplicate drinks. 814 00:53:06,890 --> 00:53:07,400 Otherwise. 815 00:53:07,400 --> 00:53:09,710 If everything checks out, then we can create a new table. 816 00:53:09,710 --> 00:53:11,150 I'll call it drink args. 817 00:53:11,960 --> 00:53:17,180 And we'll set it to the type drink properties, and we'll set it equal to an empty table. 818 00:53:17,180 --> 00:53:23,990 And from this point inside of drink args we can set the thing like owner equal to this player. 819 00:53:24,620 --> 00:53:29,840 We can set the name equal to our tool name that we just made. 820 00:53:30,780 --> 00:53:42,690 We can set pre-made key equal to this drink name or aka the key that belongs to the drink this thing. 821 00:53:44,410 --> 00:53:45,820 Will have the properties. 822 00:53:45,820 --> 00:53:52,930 So liquid properties equal to a table transparency is equal to the drink info dot transparency. 823 00:53:54,030 --> 00:53:57,480 The color is equal to drink info dot color. 824 00:53:58,160 --> 00:54:03,350 And the material is equal to drink info dot material. 825 00:54:03,530 --> 00:54:05,870 So we get the liquid properties set up. 826 00:54:06,410 --> 00:54:14,360 Drink args dot consume message is going to be equal to the drink info dot consume message. 827 00:54:14,360 --> 00:54:18,860 Again, if it's empty we'll resort to defaults that we set in here. 828 00:54:20,330 --> 00:54:23,330 Drink args dot dispense message. 829 00:54:23,940 --> 00:54:24,420 Again. 830 00:54:24,420 --> 00:54:27,870 You see, they're all popping up, so it makes it very easy to fill all this out. 831 00:54:31,740 --> 00:54:32,340 Um. 832 00:54:32,340 --> 00:54:35,040 Drink args will set the is empty. 833 00:54:37,010 --> 00:54:46,280 Equal to the drink info dot is empty and then we could do drink args dot dispense sound equal to drink 834 00:54:46,280 --> 00:54:46,940 info. 835 00:54:46,940 --> 00:54:54,710 Again I believe it's called dispense sound and drink args dot consume sound equal to drink info dot 836 00:54:54,710 --> 00:54:55,820 consume sound. 837 00:54:55,820 --> 00:55:01,820 So again we're just setting up this table to match all of the different properties that we expect for 838 00:55:01,820 --> 00:55:05,840 this particular custom type once we got that all set up. 839 00:55:06,560 --> 00:55:14,750 Then we can return true from this function, and we can return whatever gets returned from our constructor. 840 00:55:14,750 --> 00:55:16,550 So we pass the drink args. 841 00:55:17,400 --> 00:55:22,290 And actually, since we're checking for random here, what I want to make sure to do before we finish 842 00:55:22,290 --> 00:55:25,710 this up is I want to go back to our on server invoke function here. 843 00:55:25,920 --> 00:55:32,010 And when a player wants to check for a drink, if they type in random, then I want to give them a random 844 00:55:32,010 --> 00:55:32,760 drink. 845 00:55:32,760 --> 00:55:38,220 So what I could do in here is that when they're checking for a drinks existence, if they type in random 846 00:55:38,220 --> 00:55:43,980 or randomness, I want to check to see if that name belongs to the random drink that we've created in 847 00:55:43,980 --> 00:55:44,400 here. 848 00:55:44,430 --> 00:55:47,970 See if it belongs to any of these strings inside of this array. 849 00:55:48,590 --> 00:55:55,550 So what we could do is we could create an if statement and do table dot find inside of pre-made drinks, 850 00:55:55,550 --> 00:55:59,960 dot current uh names and get the random table. 851 00:56:00,230 --> 00:56:04,790 And we can check to see if this particular string exists in that table. 852 00:56:05,570 --> 00:56:12,770 If it does, then we can generate a new name by using our get random drink name function, and then 853 00:56:12,770 --> 00:56:14,630 we can just return true. 854 00:56:14,660 --> 00:56:20,300 This new name or key, and then return all the information that goes along with that key inside the 855 00:56:20,300 --> 00:56:21,200 pre-made drinks. 856 00:56:21,470 --> 00:56:22,850 Current drinks. 857 00:56:22,850 --> 00:56:25,400 And we use that name or key. 858 00:56:25,520 --> 00:56:30,530 So that way if they type in something like randomness or random, we'll create a random drink for them 859 00:56:30,530 --> 00:56:35,330 to be able to dispense and play all the drink sounds and stuff for that particular drink. 860 00:56:35,360 --> 00:56:38,060 Oh, and one more thing before I set you loose. 861 00:56:38,060 --> 00:56:40,490 Remember when we left this if statement blank here? 862 00:56:40,490 --> 00:56:44,300 We can now actually use the set owner function in here. 863 00:56:44,480 --> 00:56:49,430 And we can, you know, pass the drink args dot owner if it exists. 864 00:56:49,430 --> 00:56:54,470 So that way, you know, when we're creating a new drink object we can set the owner for the string 865 00:56:54,470 --> 00:56:55,130 object. 866 00:56:55,130 --> 00:56:59,870 And you know, parent the cup to their backpack and connect that event to it. 867 00:56:59,870 --> 00:57:05,090 So make sure you insert this function call here inside of our if statement in the constructor. 868 00:57:05,090 --> 00:57:10,940 And one more thing we need to fix here is that I accidentally set consume message twice down here. 869 00:57:10,940 --> 00:57:12,950 This should actually be consume sound. 870 00:57:12,950 --> 00:57:14,300 So make sure you fix that real quick. 871 00:57:14,300 --> 00:57:17,150 It'll be fixed in the script that's attached to the lecture. 872 00:57:18,490 --> 00:57:24,220 Otherwise, I think we have all the functionality we needed set up here inside of the server. 873 00:57:24,430 --> 00:57:31,630 So that now means we're going to have to move on to creating the module script or the class on the client, 874 00:57:31,630 --> 00:57:36,190 as well as filling out or finish filling out our pre-made drinks functions. 875 00:57:36,190 --> 00:57:42,310 And we're also going to have to fill out the local script that exists within our 294 GUI. 876 00:57:42,310 --> 00:57:48,400 And then we're also going to have to fill out our SCP 294 handler server script. 877 00:57:48,800 --> 00:57:51,350 So this script is going to be attached to the lecture. 878 00:57:51,350 --> 00:57:56,960 I'll put some extra comments in there to make it more clear as to what's going on in our server side 879 00:57:56,960 --> 00:57:57,860 class. 880 00:57:57,860 --> 00:58:00,050 Otherwise, I'll see you in the next lecture.